package main

import "math/rand"

type Solution struct {
	mapping map[int][]int
}

func Constructor(nums []int) Solution {
	mapping := make(map[int][]int)
	for i, num := range nums {
		var list []int
		if _, ok := mapping[num]; ok {
			list = mapping[num]
		}
		list = append(list, i)
		mapping[num] = list
	}
	return Solution{mapping}
}

func (this *Solution) Pick(target int) int {
	list := this.mapping[target]
	index := rand.Intn(len(list))
	return list[index]
}

/**
 * Your Solution object will be instantiated and called as such:
 * obj := Constructor(nums);
 * param_1 := obj.Pick(target);
 */
